<!DOCTYPE HTML>
<!--
	Stellar by HTML5 UP
	html5up.net | @ajlkn
	Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
	<head>
		<title>Implementation - Material Point Method</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<link rel="stylesheet" href="assets/css/main.css" />
		<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
	</head>
	<body class="is-preload">

		<!-- Wrapper -->
			<div id="wrapper">

				<!-- Header -->
					<header id="header">
						<h1>Implementation</h1>
						<p>Modeling, Simulating and Rendering</p>
					</header>

				<!-- Main -->
					<div id="main">

						<!-- Content -->
							<section id="content" class="main">
								<!-- <span class="image main"><img src="images/pic04.jpg" alt="" /></span> -->

								<p>In order to do this project, we have to conquer two main problems, simulation and rendering.</p>

								<h2>Studying</h2>
								<p>In the simulation, we start from the following two papers:<ul><li><a href="https://www.math.ucla.edu/~jteran/papers/PGKFTJM17.pdf">Multi-species simulation of porous sand and water mixtures</a></li><li><a href="https://www.math.ucla.edu/~jteran/papers/SSCTS13.pdf">A material point method for snow simulation</a></li></ul></p>
								<p>These two papers are based on the MPM method, adding more restrictions to create better effect. They provide some useful parameters we can reference. With the same configuration mentioned in the paper, though we produce the different results from theirs, these two papers still let us have good understanding how to tune the parameters.</p>

								<h2>Modeling</h2>
								<p>At first, for simplicity, only models in basic shape, such as sphere and cuboid, are used. We also built some 3D models with <a href="https://www.tinkercad.com">Tinkercad</a> and 3D Builder native in Windows 10 to enrich rendering scenes. Later, we found that <a href="http://www.danielgm.net/cc/">CloudCompare</a>, which is an open source project for 3D cloud point and mesh processing, can sample points to fill a 3D mesh. Then more complicated models appeared in our scenes.

								<h2>Simulating using material point method</h2>
								<p>
									MPM simulation is composed of the following steps:
									<ol>
										<li>Rasterize particle data to the grid</li>
										<li>Compute particle volumes and densities</li>
										<li>Compute grid forces</li>
										<li>Update velocities on grid </li>
										<li>Grid-based body collisions</li>
										<li>Solve the linear system</li>
										<li>Update deformation gradient</li>
										<li>Update particle velocities</li>
										<li>Particle-based body collisions</li>
										<li>Update particle positions</li>
									</ol>
									In each step, the properties of grids or particles are updated. Besides, updating grids or particles is highly parallel, so we use <a href="https://docs.nvidia.com/cuda/thrust/index.html">Thrust</a>, a C++ template CUDA library, to speed up the simulation by GPU acceleration. For more details, please refer to <a href="https://www.math.ucla.edu/~jteran/papers/SSCTS13.pdf">A material point method for snow simulation</a> and <a href="https://github.com/WindQAQ/MPM">our GitHub repo</a>.
								</p>

								<h2>Viewing real-time result with OpenGL</h2>
								<p><span class="image right"><img src="images/OpenGL_screenshot.png" alt=""/></span>For real-time result viewing, we use OpenGL to create a simple scene, and provide several camera views from differnet angles. Then, we bind the vertex buffer to CUDA, so that we can just use the normal OpenGL function to render the MPM particles easily.<br /> We use this scene to check if the simulation is doing well. After we get a satisfying result, we save the particle positions of each frame for OptiX™ Ray Tracing Engine.</p>

								<h2>Voxelizing and ray tracing</h2>
								<p>From saved particle positions, we load point cloud, voxelize it, and render voxels. GVDB-Voxels library is used for rendering of sparse volumetric data. Integrating with NVIDIA OptiX, it produces high quality ray-tracing result. After all point cloud data are rendered, the saved images of each frame can be combined as video.</p>

								<h2>Generating video</h2>
								<p>We use FFmpeg to combine all the images into one video. For example, we save every frame in PNG format, and use the following command to generate video. We can also specify how many images being displayed in one second (fps).</p>
								<pre><code>ffmpeg -r [fps] -pattern_type glob -i '*.png' -c:v libx264 -vf "format=yuv420p" [video name].mp4</code></pre>

							</section>

					</div>

				<!-- Footer -->
					<footer id="footer">
						<p class="copyright">&copy; Chen Li-Yu, Lin Yi-Sheng, Sung Tzu-Wei. Design: <a href="https://html5up.net">HTML5 UP</a>.</p>
					</footer>

			</div>

		<!-- Scripts -->
			<script src="assets/js/jquery.min.js"></script>
			<script src="assets/js/jquery.scrollex.min.js"></script>
			<script src="assets/js/jquery.scrolly.min.js"></script>
			<script src="assets/js/browser.min.js"></script>
			<script src="assets/js/breakpoints.min.js"></script>
			<script src="assets/js/util.js"></script>
			<script src="assets/js/main.js"></script>

	</body>
</html>
